(ns ifeast.utils.serialize
  (:require [clojure.contrib.duck-streams :as duck-streams])
  (:import java.io.PushbackReader)
  (:import java.io.FileReader)
  (:import java.io.File))

(defn serialize
  "Print a data structure to a file so that we may read it in later."
  [data-structure #^String filename]
  (duck-streams/with-out-writer
    (File. filename)
    (binding [*print-dup* true] (prn data-structure))))

(defn deserialize [filename]
  "Read in a data structure from a file." 
  (with-open [r (PushbackReader. (FileReader. filename))]
    (read r)))
